<?php
class Jedalnicek extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('news_model');
		$this->load->model('project_model');
		$this->load->model('jedalnicek_model');
		$this->load->model('register_pacient_model');
		$this->load->model('register_personal_model');
		$this->load->model('auth_model');
		$this->load->model('dieta_model');
	}
	
	public function vypis($slug)
	{
		$this->session->set_userdata('pacient', $slug);
		if (!empty($_POST)) {
			$this->jedalnicek_model->zrus_jedlo($slug);
			$this->jedalnicek_model->vlozit_jedlo($slug);
		}
		
		            $this->load->library('form_validation');
            $this->load->helper('form');
            
			$this->form_validation->set_rules('Dieta', 'Diéta', 'trim|required|xss_clean');
	if ($this->form_validation->run())
		{	
			if ($this->jedalnicek_model->prirad_inu_dietu($slug))
		          {
		  
		            	redirect('vypis');
	              }
			
		}
		
		
		$data['jedalnicek'] = $this->jedalnicek_model->povolene_jedla($slug);
		$username = $this->jedalnicek_model->zistit_login($slug);
		$data['info'] =  $this->auth_model->getUserData($username);
		$data['dieta'] = str_replace('-', ' ', $this->dieta_model->ziskaj_nazov($data['info']['Dieta']));
		$data['objednane_jedlo'] = $this->jedalnicek_model->objednane_jedlo($slug);
		$data['diagnoza'] = $this->jedalnicek_model->get_diagnoza($slug);
		$data['rodne_cislo'] = $slug;
		$data['title'] = 'NIS - Nástenka pacienta';
		$data['ingrediencie'] = $this->dieta_model->ingrediencie($data['info']['Dieta']);
		
			$diety[''] = '';

		
		$query = $this->register_pacient_model->zoznam_diet();
		foreach ($query as $row)
		{
			$diety[$row['ID']]=str_replace('-', ' ', $row['Meno']);
		}
		
		

			

		$data['diety'] = $diety;
		
		
		$this->load->view('templates/header', $data);
		$this->load->view('project/jedalnicek', $data); 	
		$this->load->view('templates/footer');
	}
	
	public function uprav_dietu($slug) { redirect('dieta/'.$slug); }
	public function uprav_diagnozu($slug) { redirect('diagnoza/'.$slug); }
	
	public function odregistrovat_pacienta($slug)
	{
		$data['title'] = 'NIS - Odregistrácia pacienta';
		$data['rodne_cislo'] = $slug;

		$this->load->view('templates/header', $data);
		$this->load->view('project/delete', $data); 	
		$this->load->view('templates/footer');
	}
	
	public function odregistrovany_pacient($slug)
	{
		$this->jedalnicek_model->odstranit_pacienta($slug);
		redirect('pacienti');		
	}

}